home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.xml;
-
- import java.io.StringReader;
- import org.xml.sax.AttributeList;
- import org.xml.sax.HandlerBase;
- import org.xml.sax.InputSource;
-
- class SchemaFlavorPeekHandler extends HandlerBase {
- private String rootName;
- private String rootPrefix;
- private String rootNS;
- private String firstChildName;
- private int elementCount = 0;
- private boolean isRoot;
- private String flavor;
- private URI uri;
- private boolean maybeXSDL;
-
- public SchemaFlavorPeekHandler(URI var1) {
- this.uri = var1;
- }
-
- public void startDocument() {
- this.isRoot = true;
- this.flavor = null;
- }
-
- public void startElement(String var1, AttributeList var2) {
- ++this.elementCount;
- if (this.isRoot) {
- boolean var3 = false;
- this.rootName = var1;
- if (this.rootName.indexOf(":") > 0) {
- this.rootPrefix = this.rootName.substring(0, this.rootName.indexOf(":") - 1);
- this.rootName = this.rootName.substring(this.rootName.indexOf(":") + 1);
- }
-
- for(int var4 = 0; var4 < var2.getLength(); ++var4) {
- String var5 = var2.getName(var4);
- if (this.rootPrefix != null && var5.equals(String.valueOf("xmlns:").concat(String.valueOf(this.rootPrefix)))) {
- this.rootNS = var2.getValue(var4);
- } else if (var5.equals("xmlns")) {
- this.rootNS = var2.getValue(var4);
- } else if (var5.equals("name")) {
- var3 = true;
- }
- }
-
- this.isRoot = false;
- if (this.rootName.equals("DCD")) {
- this.flavor = DCDFlavor.NAME;
- } else if (this.rootName.equals("DocumentDef")) {
- this.flavor = DDMLFlavor.NAME;
- } else if (this.rootName.equals("schema")) {
- if (this.rootNS != null && this.rootNS.indexOf("w3.org") >= 0) {
- if (this.rootNS.indexOf("1999/05/06") >= 0) {
- if (var3) {
- this.flavor = "xsd.1999.05.06";
- } else {
- this.flavor = "xsd.1999.12.17";
- }
- } else if (this.rootNS.indexOf("WD-xmlschema-1-19991217") > 0) {
- this.flavor = "xsd.1999.12.17";
- } else if (this.rootNS.indexOf("WD-xmlschema-1-20000225") > 0) {
- this.flavor = "xsd";
- } else if (this.rootNS.equals("http://www.w3.org/1999/XMLSchema")) {
- this.maybeXSDL = true;
- } else {
- this.flavor = "xsd";
- }
- } else {
- this.flavor = SOX2Flavor.NAME;
- }
- } else if (this.rootName.equals("Schema")) {
- String var6 = this.uri.getShortName().substring(this.uri.getShortName().lastIndexOf(46) + 1);
- if (this.rootNS != null && this.rootNS.indexOf("schemas-microsoft-com") >= 0) {
- if (var6.equals(BIZFlavor.NAME)) {
- this.flavor = BIZFlavor.NAME;
- } else {
- this.flavor = XDRFlavor.NAME;
- }
- }
- } else if (this.rootName.equals("module")) {
- this.flavor = DDMLFlavor.NAME;
- }
- } else if (this.maybeXSDL) {
- if (!var1.equals("type") && !var1.equals("datatype")) {
- if (var1.equals("simpleType") || var1.equals("complexType")) {
- this.flavor = "xsd";
- }
- } else {
- this.flavor = "xsd.1999.12.17";
- }
- }
-
- if (this.flavor != null) {
- throw new RuntimeException();
- }
- }
-
- String getRootName() {
- return this.rootName;
- }
-
- String getRootNS() {
- return this.rootNS;
- }
-
- int getElementCount() {
- return this.elementCount;
- }
-
- public String getFlavor() {
- if (this.flavor != null) {
- return this.flavor;
- } else if (this.rootName == null) {
- return DTDFlavor.NAME;
- } else if (this.maybeXSDL) {
- return "xsd";
- } else {
- return this.getElementCount() > 0 ? null : DTDFlavor.NAME;
- }
- }
-
- public InputSource resolveEntity(String var1, String var2) {
- return !var2.startsWith("urn") && var2.indexOf("/urn:") == -1 ? null : new InputSource(new StringReader(""));
- }
- }
-